//
//  EvaluationStatisticalViewController.swift
//  PropertyCommunity
//
//  Created by benwang on 2021/6/30.
//

import UIKit
import CollectionKit

class EvaluationStatisticalViewController: UIViewController {

  var collectionView = CollectionView()

  override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view.

    opacityNavigationBar(color: .designKit.background)

    view.backgroundColor = .designKit.secondaryBackground
    view.addSubview(collectionView)

    title = "评价统计"

    collectionView.snp.makeConstraints { maker in
      maker.edges.equalToSuperview()
    }

    let dataSource = ArrayDataSource<EvaluationStatisticalModel>(
      data: EvaluationStatisticalModel.items
    )

    let viewSource = ClosureViewSource<EvaluationStatisticalModel, UnitImageTextView> { item, data, index in
      item.text = data.name
    }

    let sizeSource = { (index: Int, data: EvaluationStatisticalModel, size: CGSize) in
      return CGSize(width: (size.width - 10) / 2, height: 45)
    }

    let inset = UIEdgeInsets(top: 10, left: 15, bottom: 10, right: 15)

    let itemProvider = BasicProvider<EvaluationStatisticalModel, UnitImageTextView>(
      dataSource: dataSource,
      viewSource: viewSource,
      sizeSource: sizeSource,
      layout: FlowLayout(spacing: 10)
        .inset(by: inset)
    )

    itemProvider.animator = FadeAnimator()
    itemProvider.tapHandler = { (context) in
      self.jump(to: context.data)
    }

    collectionView.provider = ComposedProvider(sections: [itemProvider])
  }

  func jump(to item: EvaluationStatisticalModel) {
    let vc = EvaluationListViewController()
    navigationController?.pushViewController(vc, animated: true)
  }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}

struct EvaluationStatisticalModel {
  let name: String
}

extension EvaluationStatisticalModel {
  static let items: [EvaluationStatisticalModel] = [
    .init(name: "石硝"),
    .init(name: "景天"),
    .init(name: "雪见"),
    .init(name: "紫萱"),
    .init(name: "徐长卿"),
    .init(name: "云庭"),
    .init(name: "蓝莹"),
  ]
}
